package parser

import (
	"cn.hughie/learngo/crawler1/engine"
	"regexp"
)

//todo 切换常量
var cp = regexp.MustCompile(`<a href="(http://album.zhenai.com/u/\d+)"[^<]*>([^<]+)</a>`)

func CityParser(contents []byte) engine.ParseResult {
	submatch := cp.FindAllSubmatch(contents, -1)
	result := engine.ParseResult{}
	for _, i := range submatch {
		//result.Items = append(result.Items, string(i[2])+" : "+string(i[1]))
		name := string(i[2])
		result.Requests = append(result.Requests, engine.Request{
			Url: string(i[1]),
			ParseFunc: func(contents []byte) engine.ParseResult {
				return ParseProfile(contents, name)
			},
		})
	}
	return result
}
